Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log warnings when an Item's semantic structure is incorrect #4613

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Feb 22, 2025

See discussion in https://community.openhab.org/t/openhab-5-semantic-model-proposal/162526/21

Sample log messages at WARN level

Item 'InvalidPoint1' (Point) has invalid semantic structure: It belongs to multiple locations [Location1, Location2]. It should only belong to one Equipment or one location, preferably not both at the same time.
Item 'InvalidPoint2' (Point) has invalid semantic structure: It belongs to multiple locations [Location1, Location1Sub]. It should only belong to one Equipment or one location, preferably not both at the same time.
Item 'InvalidPoint3' (Point) has invalid semantic structure: It belongs to multiple equipments [Equipment1, Equipment2]. A Point can only belong to at most one Equipment.
Item 'InvalidLocation1' (Location) has invalid semantic structure: It is a Number item, not a group. A location should be a Group Item.
Item 'InvalidLocation2' (Location) has invalid semantic structure: It belongs to multiple locations [Location1, Location2]. It should only belong to one location.
Item 'InvalidLocation3' (Location) has invalid semantic structure: It belongs to equipment(s) [Equipment1]. A Location can only belong to another Location, not Equipment.
Item 'InvalidLocation4' (Location) has invalid semantic structure: It belongs to equipment(s) [Equipment1]. A Location can only belong to another Location, not Equipment.
Item 'InvalidLocation5' (Location) has invalid semantic structure: It belongs to multiple locations [Location1Sub, Location1]. It should only belong to one location.
Item 'InvalidEquipment1' (Equipment) has invalid semantic structure: It belongs to multiple equipments [Equipment1, Equipment2]. An Equipment can only belong to at most one Equipment.
Item 'InvalidEquipment2' (Equipment) has invalid semantic structure: It belongs to location(s) [Location1] and equipment(s) [Equipment1]. An Equipment can only belong to one Location or another Equipment, but not both.
Item 'InvalidEquipment3' (Equipment) has invalid semantic structure: It belongs to multiple locations [Location1, Location2]. An Equipment can only belong to one Location or another Equipment.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Location (Location) and Point (Point). Location and Point tags cannot be assigned at the same time.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Location (Location) and Property (Property). Location and Property tags cannot be assigned at the same time.
Item 'TestTag' (Location) has an invalid combination of semantic tags: [Location (Location), Property (Property), Point (Point)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Point) has an invalid combination of semantic tags: Point (Point) and Equipment (Equipment). Point and Equipment tags cannot be assigned at the same time.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: Property (Property) and Equipment (Equipment). Property and Equipment tags cannot be assigned at the same time.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: [Equipment (Equipment), Property (Property), Point (Point)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Location (Location) and Equipment (Equipment). Location and Equipment tags cannot be assigned at the same time.
Item 'TestTag' (Point) has an invalid combination of semantic tags: Switch (Point) and Control (Point). Only one Point and optionally one Property tag may be assigned.
Item 'TestTag' (Point) has an invalid combination of semantic tags: Power (Property) and Level (Property). Only one Point and optionally one Property tag may be assigned.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: Lightbulb (Equipment) and Control (Point). Equipment and Point tags cannot be assigned at the same time.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: Level (Property) and Lightbulb (Equipment). Property and Equipment tags cannot be assigned at the same time.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: [Lightbulb (Equipment), Control (Point), Level (Property)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Kitchen (Location) and Control (Point). Location and Point tags cannot be assigned at the same time.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Level (Property) and Kitchen (Location). Property and Location tags cannot be assigned at the same time.
Item 'TestTag' (Location) has an invalid combination of semantic tags: [Kitchen (Location), Control (Point), Level (Property)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: Lightbulb (Equipment) and Kitchen (Location). Equipment and Location tags cannot be assigned at the same time.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: Speaker (Equipment) and Lightbulb (Equipment). Only one Equipment tag may be assigned.
Item 'TestTag' (Location) has an invalid combination of semantic tags: Kitchen (Location) and FirstFloor (Location). Only one Location tag may be assigned.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: [Lightbulb (Equipment), Switch (Point), Kitchen (Location)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Equipment) has an invalid combination of semantic tags: [Lightbulb (Equipment), Kitchen (Location), Power (Property)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.
Item 'TestTag' (Point) has an invalid combination of semantic tags: [Switch (Point), Kitchen (Location), Power (Property), Lightbulb (Equipment)]. An item may only have one tag of Location, Equipment, or Point type. A Property tag may be assigned in conjunction with a Point tag.

A Point that belongs to an Equipment and a Location will generate an INFO log. This allows user to set the log level to WARN to not see them.

Item 'InvalidPoint3' (Point) belongs to location [SetupLocation] and equipment [SetupEquipment].

May require better wording to more accurately convey the meaning.

@jimtng jimtng requested a review from a team as a code owner February 22, 2025 02:08
@jimtng
Copy link
Contributor Author

jimtng commented Feb 22, 2025

@rkoshak FYI. I'd like to tag JustinG too but I don't know his github name.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-5-semantic-model-proposal/162526/61

@jimtng jimtng force-pushed the item-semantic-validator branch from 57c1e31 to 59920f1 Compare February 22, 2025 02:35
@mherwege
Copy link
Contributor

@jimtng This is very interesting.

Note that I put in logic to validate model changes in the PR for model drag drop: openhab/openhab-webui#2970

Seeing the checks you have here, it looks like I have missed the special cases (point in equipment with also location set on that item). I may have to make a slight change to support that, but first want to get the main cases reviewed and supported there.

I. Am just wondering if there would be a more intelligent way to keep these rules in sync. But then again, the logic must be in the UI (and not a REST call check), as this would be impossible for checks during the drag action.

@rkoshak
Copy link

rkoshak commented Feb 22, 2025

@JustinGeorgi is Justin's Github tag.

A Point that belongs to an Equipment and a Location will generate an INFO log. This allows user to set the log level to WARN to not see them.

I like this idea.

May require better wording to more accurately convey the meaning.

Maybe just add to the message why this is being logged.

Item 'InvalidPoint3' (Point) belongs to location [SetupLocation] and equipment [SetupEquipment] which could indicate a problem.

I don't know if that's any better.

@jimtng
Copy link
Contributor Author

jimtng commented Feb 22, 2025

Item 'InvalidPoint3' (Point) belongs to location [SetupLocation] and equipment [SetupEquipment] which could indicate a problem.

I don't know if that's any better.

I'm trying to avoid mentioning "problem", in the case when it's intentional.

May require better wording to more accurately convey the meaning.

I'm more referring to all the other messages I came up above, so if you have other suggestions, I'd like to hear them.

Am just wondering if there would be a more intelligent way to keep these rules in sync. But then again, the logic must be in the UI (and not a REST call check), as this would be impossible for checks during the drag action.

I see, that it's tricky, primarily that it would be slow to have to call REST every time you do a test against potential drop target, not to mention caching issues. Perhaps it's easier to just duplicate the logic and write a comment in the UI code to refer to the core code? I didn't even think about the drag and drop code, and more about just displaying a red warning / icon on the item or model page. So maybe your code could be written so the validation can be called there too. Alternatively it can be refactored later.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/configuration-of-multiple-items/162674/7

@jimtng jimtng changed the title Provide a hint when an Item's semantic structure is incorrect Log warnings when an Item's semantic structure is incorrect Feb 24, 2025
@jimtng jimtng force-pushed the item-semantic-validator branch from 59920f1 to 24642e1 Compare February 24, 2025 13:04
@rkoshak
Copy link

rkoshak commented Feb 24, 2025

I'm more referring to all the other messages I came up above, so if you have other suggestions, I'd like to hear them.

That was the only one that stood out.

@clinique
Copy link
Contributor

clinique commented Mar 1, 2025

Shouldn't the warning go also to Health Checks provided by the UI ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants